

package cn.zzuli.anew;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;

public class MusicActivity extends AppCompatActivity {
    private MediaPlayer mp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music);
        mp = MediaPlayer.create(this, R.raw.hgtc);
    }

    /*public void play(View V) {
        Cursor cursor= getContentResolver().
                query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        null,null,null,null);
        while(cursor.moveToNext()){
           // MediaStore.Audio.Media.TITLE;
            String title=cursor.getString(cursor.getColumnIndex("Title"));
            System.out.println(title);
        }
    }*/


    //方法一：
    public void play(View V) {
        mp.start();
    }

    public void pause(View V) {
        mp.pause();
    }

    public void stop(View V) {
        mp.stop();
    }

}